package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.JuTiShangPin;
import com.ysd.util.DBManager;

public class JuTiShangPinDaoImpl {
	/**
	 * 根据分类ID查询对应的产品列表
	 * @param chanPinId 产品分类id
	 * @return
	 */
	public List<JuTiShangPin> getJuTiShangPinList(int chanPinId){
		List<JuTiShangPin> juTiShangPinList = new ArrayList<JuTiShangPin>();
		Connection conn =DBManager.getConnection();
		Statement st = null;
		ResultSet rs = null;
		
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from juTiShangPin where chanPinId="+chanPinId);
			while(rs.next()) {
				int shangPinId = rs.getInt("shangPinId");
				String shangPinName = rs.getString("shangPinName");
				int shouJia = rs.getInt("shouJia");
				String pinPai = rs.getString("pinPai");
				String chanDi =rs.getString("chanDi");
				String neiCun = rs.getString("neiCun");
				String yunXing = rs.getString("yanSe");
				String yanSe = rs.getString("yanSe");
				String chanPinImg =rs.getString("chanPinImg");
				JuTiShangPin juTiShangPin = new JuTiShangPin(shangPinId, shangPinName, shouJia, pinPai, chanDi, neiCun, yunXing, yanSe, chanPinImg);
				juTiShangPinList.add(juTiShangPin);
			}
			return juTiShangPinList;
		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	
	public List<JuTiShangPin> getJuTiShangPin(int shangPinId){
		List<JuTiShangPin> juTiShangPinList = new ArrayList<JuTiShangPin>();
		Connection conn =DBManager.getConnection();
		Statement st = null;
		ResultSet rs = null;
		
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from juTiShangPin where shangPinId="+shangPinId);
			while(rs.next()) {
				int spId = rs.getInt("shangPinId");
				String shangPinName = rs.getString("shangPinName");
				int shouJia = rs.getInt("shouJia");
				String pinPai = rs.getString("pinPai");
				String chanDi =rs.getString("chanDi");
				String neiCun = rs.getString("neiCun");
				String yunXing = rs.getString("yanSe");
				String yanSe = rs.getString("yanSe");
				String chanPinImg =rs.getString("chanPinImg");
				JuTiShangPin juTiShangPin = new JuTiShangPin(spId, shangPinName, shouJia, pinPai, chanDi, neiCun, yunXing, yanSe, chanPinImg);
				juTiShangPinList.add(juTiShangPin);
			}
			return juTiShangPinList;
		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
}
